package com.batsoft.trade.disruptor.opp;

import com.batsoft.trade.disruptor.base.BaseQueueHelper;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.WaitStrategy;
import com.lmax.disruptor.WorkHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/8/27 13:52
 * <p>
 * 定义
 */
@Component
public class OppDataEventQueueHelper extends BaseQueueHelper<OppData, OppDataEvent, OppDataEventHandler> implements InitializingBean {

    private static final int QUEUE_SIZE = 1024;

    @Autowired
    private List<OppDataEventHandler> oppDataEventHandler;


    @Override
    protected int getQueueSize() {
        return QUEUE_SIZE;
    }

    @Override
    protected com.lmax.disruptor.EventFactory eventFactory() {
        return new OppEventFactory();
    }

    @Override
    protected WorkHandler[] getHandler() {
        int size = oppDataEventHandler.size();
        return oppDataEventHandler.toArray(new WorkHandler[size]);
    }

    @Override
    protected WaitStrategy getStrategy() {
        return new BlockingWaitStrategy();
        //return new YieldingWaitStrategy();
    }

    @Override
    public void afterPropertiesSet() {
        this.init();
    }
}